#-*- coding: utf-8 -*-

#This file is part of PyAero library.
#
# PyAero is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyAero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with PyAero.  If not, see <http://www.gnu.org/licenses/>.

__author__ = u'Guillaume Baty'
__copyright__ = u'Copyright 2011-2012 (C) andheo'
__credits__ = [u'Guillaume Baty']
__license__ = "GNU Lesser General Public License"

from pyLot.dataconverter import DataConverterHandler

class DataCreatorHandler(DataConverterHandler):

  def __init__(self):
    DataConverterHandler.__init__(self)
    self._updateGraph()

  def _updateGraph(self):
    self.creators = {}
    self.viewers = {}

    for obj_class in self.pm.get_extensions('pyLot.qtgui.creators'):
      try :
        datarepr = self.reprs[obj_class.datarepr_id]
      except KeyError :
        print 'Pb loading %s' % obj_class
      else :
        obj = obj_class(datarepr)
        obj_id = obj.identifier
        self.creators[obj_id] = obj
        self.graph.add_node(obj_id)
        self.graph.add_edge(obj_id, datarepr.identifier)

#    for obj_class in self.pm.get_extensions('pyLot.qtgui.viewers'):
#      print obj_class


    self.nodes.update(self.creators)

